#pragma once
#pragma warning(disable:4996)       // disable checked iterator errors http://msdn.microsoft.com/en-us/library/aa985965(VS.80).aspx 

//
// Copyright (C) 2011 - 2013 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1

#include <Macros.h>
#include <ValueHelpers.h>
#include <Settings.h>

#pragma unmanaged 
#include <ql\instruments\makevanillaswap.hpp>
#include <boost/smart_ptr/detail/spinlock.hpp>
#pragma managed 

using namespace System;
using namespace QuantLib;
using namespace Cephei;
using namespace Cephei::Core;
using namespace PLATFORM::Collections;

using namespace Cephei::QL::Times;
using namespace Cephei::QL::Indexes;
using namespace Cephei::QL::Termstructures;
using namespace Cephei::QL;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
namespace Cephei { namespace QL { namespace Instruments {
	//////////////////////////////////////////////////////////////////////////////////////////////
	// implementation of IMakeVanillaSwap
	public ref class CMakeVanillaSwap  : 
            public Cephei::QL::Instruments::IMakeVanillaSwap
	{
	protected: 
		boost::shared_ptr<QuantLib::MakeVanillaSwap>* _ppMakeVanillaSwap;
        boost::detail::spinlock* _pSpinlock;
#ifdef HANDLE
		QuantLib::Handle<QuantLib::MakeVanillaSwap>* _phMakeVanillaSwap;
#endif
		Object^ _MakeVanillaSwapOwner;     // reference to object that manages the storage for this object
	internal:
		CMakeVanillaSwap (Cephei::QL::Times::IPeriod^ swapTenor, Cephei::QL::Indexes::IIborIndex^ iborIndex, Microsoft::FSharp::Core::FSharpOption<Double>^ fixedRate, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IPeriod^>^ forwardStart);
        CMakeVanillaSwap (boost::shared_ptr<QuantLib::MakeVanillaSwap>& childNative, Object^ owner);
        CMakeVanillaSwap (QuantLib::MakeVanillaSwap& childNative, Object^ owner);
        CMakeVanillaSwap (CMakeVanillaSwap^ copy);
        CMakeVanillaSwap (PLATFORM::Type^ t);
#ifdef STRUCT
        CMakeVanillaSwap (QuantLib::MakeVanillaSwap childNative);
#endif       
#ifdef HANDLE
		CMakeVanillaSwap (QuantLib::Handle<QuantLib::MakeVanillaSwap>& childNative, Object^ owner);
		CMakeVanillaSwap (QuantLib::Handle<QuantLib::MakeVanillaSwap> childNative);
#endif
		virtual ~CMakeVanillaSwap ();
		!CMakeVanillaSwap ();

	internal:
		QuantLib::MakeVanillaSwap& GetReference ();
		boost::shared_ptr<QuantLib::MakeVanillaSwap>& GetShared ();
		QuantLib::MakeVanillaSwap* GetPointer ();
        void SetMakeVanillaSwap (boost::shared_ptr<QuantLib::MakeVanillaSwap> native)
        {
            if (_ppMakeVanillaSwap != NULL)
                delete _ppMakeVanillaSwap;
            _ppMakeVanillaSwap = new boost::shared_ptr<QuantLib::MakeVanillaSwap> (native);
            
        }
#ifdef HANDLE
		QuantLib::Handle<QuantLib::MakeVanillaSwap>& GetHandle ();
#endif
		virtual bool HasNative () ;
		void Lock ()
		{
			if (Cephei::QL::Settings::_ReferenceLocking)
    			_pSpinlock->lock ();
		}
		void Unlock ()
		{
			_pSpinlock->unlock ();
		}
    public:
		virtual Cephei::QL::Instruments::IMakeVanillaSwap^ ReceiveFixed (Microsoft::FSharp::Core::FSharpOption<Boolean>^ flag) ;
		virtual Cephei::QL::Instruments::IMakeVanillaSwap^ WithDiscountingTermStructure (Cephei::QL::Termstructures::IYieldTermStructure^ discountCurve) ;
		virtual Cephei::QL::Instruments::IMakeVanillaSwap^ WithEffectiveDate (DateTime effectiveDate) ;
		virtual Cephei::QL::Instruments::IMakeVanillaSwap^ WithFixedLegCalendar (Cephei::QL::Times::ICalendar^ cal) ;
		virtual Cephei::QL::Instruments::IMakeVanillaSwap^ WithFixedLegConvention (QL::Times::BusinessDayConventionEnum bdc) ;
		virtual Cephei::QL::Instruments::IMakeVanillaSwap^ WithFixedLegDayCount (Cephei::QL::Times::IDayCounter^ dc) ;
		virtual Cephei::QL::Instruments::IMakeVanillaSwap^ WithFixedLegEndOfMonth (Microsoft::FSharp::Core::FSharpOption<Boolean>^ flag) ;
		virtual Cephei::QL::Instruments::IMakeVanillaSwap^ WithFixedLegFirstDate (DateTime d) ;
		virtual Cephei::QL::Instruments::IMakeVanillaSwap^ WithFixedLegNextToLastDate (DateTime d) ;
		virtual Cephei::QL::Instruments::IMakeVanillaSwap^ WithFixedLegRule (QL::Times::DateGeneration::RuleEnum r) ;
		virtual Cephei::QL::Instruments::IMakeVanillaSwap^ WithFixedLegTenor (Cephei::QL::Times::IPeriod^ t) ;
		virtual Cephei::QL::Instruments::IMakeVanillaSwap^ WithFixedLegTerminationDateConvention (QL::Times::BusinessDayConventionEnum bdc) ;
		virtual Cephei::QL::Instruments::IMakeVanillaSwap^ WithFloatingLegCalendar (Cephei::QL::Times::ICalendar^ cal) ;
		virtual Cephei::QL::Instruments::IMakeVanillaSwap^ WithFloatingLegConvention (QL::Times::BusinessDayConventionEnum bdc) ;
		virtual Cephei::QL::Instruments::IMakeVanillaSwap^ WithFloatingLegDayCount (Cephei::QL::Times::IDayCounter^ dc) ;
		virtual Cephei::QL::Instruments::IMakeVanillaSwap^ WithFloatingLegEndOfMonth (Microsoft::FSharp::Core::FSharpOption<Boolean>^ flag) ;
		virtual Cephei::QL::Instruments::IMakeVanillaSwap^ WithFloatingLegFirstDate (DateTime d) ;
		virtual Cephei::QL::Instruments::IMakeVanillaSwap^ WithFloatingLegNextToLastDate (DateTime d) ;
		virtual Cephei::QL::Instruments::IMakeVanillaSwap^ WithFloatingLegRule (QL::Times::DateGeneration::RuleEnum r) ;
		virtual Cephei::QL::Instruments::IMakeVanillaSwap^ WithFloatingLegSpread (Double sp) ;
		virtual Cephei::QL::Instruments::IMakeVanillaSwap^ WithFloatingLegTenor (Cephei::QL::Times::IPeriod^ t) ;
		virtual Cephei::QL::Instruments::IMakeVanillaSwap^ WithFloatingLegTerminationDateConvention (QL::Times::BusinessDayConventionEnum bdc) ;
		virtual Cephei::QL::Instruments::IMakeVanillaSwap^ WithNominal (Double n) ;
		virtual Cephei::QL::Instruments::IMakeVanillaSwap^ WithRule (QL::Times::DateGeneration::RuleEnum r) ;
		virtual Cephei::QL::Instruments::IMakeVanillaSwap^ WithTerminationDate (DateTime terminationDate) ;
		virtual Cephei::QL::Instruments::IMakeVanillaSwap^ WithType (QL::Instruments::VanillaSwap::TypeEnum type) ;
		virtual Cephei::QL::Instruments::IMakeVanillaSwap^ WithPricingEngine (Cephei::QL::IPricingEngine^ engine) ;
    };
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Factory class
//z	[FactoryFor(Core::Generic::ICoCell<Cephei::QL::Instruments::IMakeVanillaSwap^>::typeid)]
	[FactoryFor(Cephei::QL::Instruments::IMakeVanillaSwap::typeid)]
	[FactoryFor(Cephei::QL::Instruments::IMakeVanillaSwap_Factory::typeid)]
	public ref class CMakeVanillaSwap_Factory sealed : public IMakeVanillaSwap_Factory
	{
	public:
        virtual IMakeVanillaSwap^ Create (Cephei::QL::Times::IPeriod^ swapTenor, Cephei::QL::Indexes::IIborIndex^ iborIndex, Microsoft::FSharp::Core::FSharpOption<Double>^ fixedRate, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IPeriod^>^ forwardStart);
    };
   
/*Cephei*/ } /*QL*/ } /*Instruments */}
